@page "/app/{AppId}/credentials/list"
@inherits BaseApplicationPage

@inject IScopedPasswordlessClient PasswordlessClient;
@inject ICurrentContext CurrentContext;

<Page Title="Users">
    @if (MaxUsers.HasValue)
    {
        <Panel Header="Summary">
            @if (MaxUsers <= Users!.Count)
            {
                <Alert Style="@ContextualStyles.Danger">
                    @Users.Count out of your @MaxUsers user limit are currently in use. Consider upgrading your plan to accommodate more users.
                </Alert>
            }
            else
            {
                <Alert Style="@ContextualStyles.Info">
                    @Users.Count users of your @MaxUsers user limit are currently in use.
                </Alert>
            }
        </Panel>
    }
    
    <Panel>
        @if (Users != null)
        {
            <Table ColumnHeaders="_columnHeaders" EmptyMessage="@EmptyMessage">
                @foreach (var user in Users)
                {
                    <tr>
                        <td class="whitespace-nowrap td-indent">
                            <a href="/app/@CurrentContext.AppId/credentials/user/@user.UserId">@user.UserId</a>
                        </td>
                        <td class="whitespace-nowrap">@user.Aliases</td>
                        <td class="whitespace-nowrap">@user.CredentialCount</td>
                        <td class="whitespace-nowrap">
                            @if (user.LastSeen.HasValue)
                            {
                                <LocalDateTime Value="user.LastSeen.Value" />
                            }
                        </td>
                    </tr>
                }
            </Table>
        }
    </Panel>
</Page>